package com.texaco.chapasFutbol.scene;

import org.andengine.entity.modifier.AlphaModifier;
import org.andengine.entity.modifier.IEntityModifier;
import org.andengine.entity.modifier.SequenceEntityModifier;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.util.color.Color;
import org.andengine.util.progress.IProgressListener;

import com.texaco.chapasFutbol.ChapasFutbolActivity;
import com.texaco.chapasFutbol.R;
import com.texaco.chapasFutbol.entidades.Game;
import com.texaco.chapasFutbol.resources.Resources;

/**
 * Clase que implementa la escena del splash.
 * @author Manuel
 */
public class SplashScene extends SceneBase{

	public SplashScene(Game game){
		super(game);
		this.setBackground(new Background(Color.WHITE)); 
	}

	@Override
	public void initAsync(IProgressListener pProgressListener) {
		final ChapasFutbolActivity activity = game.getActivity();
		final IEntityModifier splashEntityModifier = new SequenceEntityModifier(
				new AlphaModifier(1.5f, 1, 0),
				new AlphaModifier(1.5f, 0, 1)
		);
		
		Sprite splash = new Sprite(
				(activity.getEngine().getCamera().getWidth()/2)-(activity.mSplashTextureAtlas.getWidth()/2), 
				(activity.getEngine().getCamera().getHeight()/2)-(activity.mSplashTextureAtlas.getHeight()/2), 
				activity.mSplashTextureAtlas, 
				activity.getVertexBufferObjectManager()) {
		};
		
		// TODO: pedir a Pedro un recurso para el splash con mayor resolución.
//		Sprite splash = new Sprite(
//				(activity.getEngine().getCamera().getWidth()/2)-(700/2), 
//				(activity.getEngine().getCamera().getHeight()/2)-(700/2), 
//				activity.mSplashTextureAtlas, 
//				activity.getVertexBufferObjectManager()) {
//		};
		
		splash.registerEntityModifier(splashEntityModifier);
//		splash.setWidth(700);
//		splash.setHeight(700);
		
//		Text textoParaContinuar = new Text(170, 600, activity.getFontMap().get(Resources.FONT_SPLASH),
//				activity.getString(R.string.texto_splash), 50,
//				activity.getVertexBufferObjectManager());
		
		this.attachChild(splash);
//		this.attachChild(textoParaContinuar);
		
//		this.setOnSceneTouchListener(new IOnSceneTouchListener() {
//			public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
//				if(pSceneTouchEvent.isActionUp()) {
//					activity.getSoundHandler().playFx(Resources.SOUND_CLICK);
//					game.loadMenuPrincipalScene();
//				}
//				return true;
//			}
//		});		
	}

	@Override
	protected void update() {
		// TODO Auto-generated method stub
	}

	@Override
	protected boolean async() {
		return false;
	}
}